/*************************************************************************
	> File Name: main.c
	> Author: Angel Criss
	> Mail: abbytsing@gmail.com 
	> Created Time: 日  8/10 10:22:35 2014
 ************************************************************************/

#include<stdio.h>
#include <stdlib.h>
#include "list.h"

void showmoives (Item item);

int main(void)
{
  List movies;
  Item temp;
  
  //初始化
  InitailizeList (&movies);
  if(ListIsFull(&movies))
  {
    fprintf(stderr,"No memery left");   // 内存用完...
    exit(1);
  }
  
  //收集并储存
  puts("Enter first moive title: ");
  
  while(gets(temp.title)!=NULL && temp.title[0]!='\0')
  {
    puts("Enter the rating <0-10>: ");
    
    scanf("%d",&temp.rating);
    
    while(getchar()!='\n')
      continue;
    
    if(AddItem(temp,&movies)==false)
    {
      fprintf(stderr,"Problem allocating memery\n");
      break;
    }
    
    if(ListIsFull(&movies))
    {
      puts("The list is now full");
      break;
    }
    
    puts("Enter next movies title(empty to quit):");
  }
  
  //显示
  if(ListIsEmpty(&movies))
    printf("No data entered");
  else
  {
    printf("Here is the movies list:\n\n");
    Traverse(&movies,showmoives);
  }
  
  printf("\nYou entered %d movies.\n",ListItemCount(&movies));
  
  //清除
  EmptyTheList(&movies);
  printf("All Done\n");
  return 0;
}


void showmoives(Item item)
{
  printf("Movie: %s Rating: %d\n",item.title,item.rating);
}
